package fragment;

import holder.SubjectHolder;

import java.util.List;
import java.util.Random;

import factory.ListViewFactory;

import protocol.SubjectProtocol;

import base.BaseFragment;
import base.BaseHolder;
import base.LoadingPager.LoadResult;
import base.SuperBaseAdapter;
import bean.SubjectInfoBean;
import utils.UIUtils;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.TextView;
/**
 * 专题页面的Fragment
 * @author Anson-pc
 *
 */
public class SubjectFragment extends BaseFragment {

	private List<SubjectInfoBean> datas;

	/**
	 * 
	 */
	@Override
	protected LoadResult initData() {
		SystemClock.sleep(2000);
		//成功
		//失败
		//错误
		
		//随机返回状态
		SubjectProtocol protocol = new SubjectProtocol();
		try {
			datas = protocol.loadData(0);
			return checkState(datas);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return LoadResult.ERROR;
		}
	}

	@Override
	protected View initSuccessView() {
		ListView listView = ListViewFactory.createListView();
		listView.setAdapter(new SubjectAdapter(listView, datas));
		return listView;
	}

	/**
	 * 专题的适配器
	 * @author Anson-pc
	 *
	 */
	class SubjectAdapter extends SuperBaseAdapter<SubjectInfoBean>{

		public SubjectAdapter(AbsListView ablistView,
				List<SubjectInfoBean> mDatas) {
			super(ablistView, mDatas);
		}

		@Override
		protected BaseHolder<SubjectInfoBean> getSpecialHolder(int position) {
			return new SubjectHolder();
		}
		
		/**
		 * 加载更多
		 */
		@Override
		protected boolean hasLoadMore() {
			return false;
		}
		
	}
}
